package com.wandian.ui.controls
{
	import com.wandian.utils.Res;

	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;

	import com.wandian.utils.GDI;

	public class Alert extends Sprite
	{
		public var okBtn:WanButton=new WanButton("alertOK");
		private var message:UITextField=new UITextField(420, 50, 0xFFFFFF, 13);
		private static var instance:Alert=new Alert()
		private static var parent:Sprite;
		private static var shown:Boolean=false

		public function Alert()
		{
			GDI.drawBitmapData(this.graphics, 0, 0, Res.get("alertBG"))
			okBtn.x=180
			okBtn.y=256
			this.addChild(okBtn);
			message.x=15
			message.y=120			
			//message.multiline=true;
			this.addChild(message);
			okBtn.setClickHandler(close)
		}

		private function close():void
		{
			shown=false
			Alert.parent.graphics.clear()
			Alert.parent.removeChild(instance);
		}

		public static function init(parent:Sprite):void
		{
			Alert.parent=parent
		}

		public static function show(str:String):void
		{
			if (!shown)
			{
				var g:Graphics=Alert.parent.graphics
				var stage:Stage=Alert.parent.stage
				g.beginFill(0x000000, 0.1)
				g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
				instance.x=(stage.stageWidth - instance.width) / 2
				instance.y=(stage.stageHeight - instance.height) / 2
				Alert.parent.addChild(instance);
			}
			shown=true
			instance.message.text=str
		}
	}
}
